using System.ComponentModel;
using Meebey.SmartIrc4net;

namespace Thunder.IrcClient.MessageParser
{
    /// <summary>
    /// Base class for all message parsers 
    /// </summary>
    public abstract class MessageParser : IMessageParser
    {
        /// <summary>
        /// Gets the <see cref="MessageManager"/> instance
        /// </summary>
        public MessageManager Manager { get; private set; }

        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public abstract ReceiveType MessageType { get; }

        /// <summary>
        /// This method is invoked when a message should be parsed
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        public void Parse(CancelMessageProcessingEventArgs args)
        {
            this.ParseCore(args);      
        }

        /// <summary>
        /// This method is invoked during message parsing.
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        protected virtual void ParseCore(CancelMessageProcessingEventArgs args)
        {
        }

        /// <summary>
        /// Initializes the message parser
        /// </summary>
        /// <param name="manager">The <see cref="MessageManager"/> instance</param>
        public void Initialize(MessageManager manager)
        {
            this.Manager = manager;

            this.InitializeCore();
        }

        /// <summary>
        /// This method is invoked during initialization
        /// </summary>
        protected virtual void InitializeCore()
        {
        }
    }
}